import 'dart:ffi';

import 'package:eplorex/pages/my/profile/ButtonWidget.dart';
import 'package:eplorex/utils/ColorUtil.dart';
import 'package:eplorex/utils/HttpUtil.dart';
import 'package:flutter/material.dart';

import '../../search_page.dart';

class EditUserSchoolPage extends StatefulWidget {
  EditUserSchoolPage({super.key, this.school,required this.valueChanged});

  String? school;

  ValueChanged valueChanged;

  @override
  State<EditUserSchoolPage> createState() => _EditUserSchoolPageState();
}

class _EditUserSchoolPageState extends State<EditUserSchoolPage> {
  TextStyle? _textStyleDefault = TextStyle(fontSize: 20);

  void _submit(BuildContext context) {
    if (widget.school != null) {
      HttpUtil.getInstance()
          .post('/api/user/v1/my/profile/edit/school', data: widget.school);
       widget.valueChanged.call(widget.school);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: ButtonWidget(
          width: 80,
          height: 50,
          onPressed: () {
            Navigator.pop(context);
          },
          highlightedColor: ColorUtil.hexColor(0xf7f7f7),
          bgColor: ColorUtil.hexColor(0xffffff),
          bgHighlightedColor: ColorUtil.hexColor(0xf7f7f7),
          enabled: true,
          bgDisableColor: Colors.grey,
          borderRadius: 8.0,
          child: Text(
            "取消",
            textAlign: TextAlign.center,
            softWrap: true,
            style: TextStyle(
              fontSize: 16,
              fontWeight: FontWeight.w500,
              fontStyle: FontStyle.normal,
              color: ColorUtil.hexColor(0xA1A1A1),
              decoration: TextDecoration.none,
            ),
          ),
        ),
        title: Text("编辑学校"),
        actions: [
          ButtonWidget(
            width: 80,
            height: 50,
            onPressed: () {
              Navigator.pop(context);
              _submit(context);
            },
            highlightedColor: ColorUtil.hexColor(0xf7f7f7),
            bgColor: ColorUtil.hexColor(0xffffff),
            bgHighlightedColor: ColorUtil.hexColor(0xf7f7f7),
            enabled: true,
            bgDisableColor: Colors.grey,
            borderRadius: 8.0,
            child: Text(
              "确定",
              textAlign: TextAlign.center,
              softWrap: true,
              style: TextStyle(
                fontSize: 16,
                fontWeight: FontWeight.w400,
                fontStyle: FontStyle.normal,
                color: ColorUtil.hexColor(0x338FFF),
                decoration: TextDecoration.none,
              ),
            ),
          )
        ],
      ),
      body: Container(
        child: Column(
          children: [
            ListTile(
              title: Text(
                '名字',
                style: _textStyleDefault,
              ),
              trailing: Wrap(
                crossAxisAlignment: WrapCrossAlignment.center,
                children: [
                  Text(
                    widget.school ?? "",
                    style: TextStyle(fontSize: 16),
                  ),
                  Image(
                    image: AssetImage("images/arrow_right_icon.png"),
                    width: 20,
                  )
                ],
              ),
              splashColor: Colors.black,
              onTap: () {
                Navigator.of(context)
                    .push(MaterialPageRoute(builder: (_) => SearchPage()));
              },
            ),
          ],
        ),
      ),
    );
  }
}
